package com.sduept.nwld.dataserver.interceptors;

import com.sduept.cim.ledger.manager.LineSegmentLedgerManager;
import com.sduept.cim.ledger.manager.SubstationLedgerManager;
import com.sduept.cim.model.core.Substation;
import com.sduept.cim.model.wires.ACLineSegment;
import com.sduept.cim.model.wires.DcLinesegment;
import org.springframework.beans.factory.annotation.Autowired;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

/**
 * @author     Xiaopy
 * @version    V1.0
 * @Date       2018年9月29日 上午10:54:49
 */
public class CimModeCreateOrUpdatelInterceptor {

	@Autowired
	private SubstationLedgerManager stationLedgerM;
	@Autowired
	private LineSegmentLedgerManager lineLedgerM;

	
	@AroundInvoke
	public Object methodInterceptor(InvocationContext ctx) throws Exception {
		Object[] parameter = ctx.getParameters();
		Object proceed = ctx.proceed();
		String cla = parameter[0].getClass().getSimpleName();
		if("Substation".equals(cla)) {
			Substation station = (Substation) proceed;
			stationLedgerM.createSubstationLedgerBySubstation(station);
		} else if ("ACLineSegment".equals(cla)) {
			ACLineSegment acline = (ACLineSegment) proceed;
			lineLedgerM.createOrUpdateByAcLine(acline);
		} else if ("DcLinesegment".equals(cla)) {
			DcLinesegment dcline = (DcLinesegment) proceed;
			lineLedgerM.createOrUpdateByDcLine(dcline);
		}
		return proceed;
	}
}
